package com.neusoft.weekreport.component.controller;

import com.neusoft.weekreport.component.bizService.GroupRefUserBizService;
import com.neusoft.weekreport.component.req.GroupRefUserByGroupIdReq;
import com.neusoft.weekreport.component.req.GroupRefUserDeleteUserReq;
import com.neusoft.weekreport.component.resp.GroupRefUserByGroupIdResp;
import com.neusoft.weekreport.component.resp.ResponseBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@RestController
@EnableTransactionManagement
@RequestMapping("/goupUser")
public class GroupRefUserController {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    GroupRefUserBizService groupRefUserBizService;

    //通过groupId查询关联用户
    @RequestMapping(value = "/group_ref_userInList",method = RequestMethod.GET)
    public ResponseBean<GroupRefUserByGroupIdResp> getUserByGroupId(GroupRefUserByGroupIdReq req){
        ResponseBean<GroupRefUserByGroupIdResp> responseBean = new ResponseBean<>();
        try{
            GroupRefUserByGroupIdResp resp = groupRefUserBizService.getUserByGroupId(req);
            responseBean = new ResponseBean(HttpStatus.OK.value(),"查询用户列表成功",resp);
        }catch (Exception e){
            responseBean.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            responseBean.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
            logger.error(e.toString());
        }
        return responseBean;
    }

    //删除关联用户
    @RequestMapping(value = "/group_ref_user",method = RequestMethod.DELETE)
    public ResponseBean deleteUserByUserId(@RequestBody GroupRefUserDeleteUserReq req, HttpServletRequest request){
        ResponseBean responseBean = new ResponseBean();
        try{
            groupRefUserBizService.deleteUserByUserId(req);
            responseBean = new ResponseBean(HttpStatus.OK.value(),"删除用户成功",responseBean);
        }catch (Exception e){
            responseBean.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            responseBean.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
            logger.error(e.toString());
        }
        return responseBean;
    }

    //查询未关联用户
    @RequestMapping(value = "/group_ref_userNoList",method = RequestMethod.GET)
    public ResponseBean<GroupRefUserByGroupIdResp> getUserNoByGroupId(GroupRefUserByGroupIdReq req,HttpServletRequest request){
        ResponseBean<GroupRefUserByGroupIdResp> responseBean = new ResponseBean();
        try{
            GroupRefUserByGroupIdResp resp = groupRefUserBizService.getUserNoByGroupId(req);
            responseBean = new ResponseBean(HttpStatus.OK.value(),"查询未关联用户成功",resp);

        }catch (Exception e){
            responseBean.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            responseBean.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
            logger.error(e.toString());
        }
        return responseBean;
    }
    //添加关联用户
    @RequestMapping(value = "/group_ref_user",method = RequestMethod.POST)
    public ResponseBean addUserListByGroupId(@RequestBody GroupRefUserDeleteUserReq req,HttpServletRequest request){
        ResponseBean responseBean = new ResponseBean();
        try{
            groupRefUserBizService.addUserListByGroupId(req);
            responseBean = new ResponseBean(HttpStatus.OK.value(),"添加关联用户成功",responseBean);

        }catch (Exception e){
            responseBean.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            responseBean.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
            logger.error(e.toString());
        }
        return responseBean;

    }


}